package com.sunmouse.toolkit.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sunmouse.toollib.adapter.BasicRecyclerAdapter;
import com.sunmouse.toollib.utils.StringUtils;
import com.sunmouse.toolkit.R;
import com.sunmouse.toolkit.bean.MediaBean;
import com.sunmouse.toolkit.widget.progress.LoadBar;

import java.util.List;

/**
 * Created by leiyun on 2018/5/23.
 */
public class LoadAdapter extends BasicRecyclerAdapter<MediaBean,LoadAdapter.ViewHolder> {


    public LoadAdapter(List<MediaBean> list, Context context) {
        super(list, context);
    }

    @Override
    protected View bindConvertView(LayoutInflater inflater, ViewGroup parent, int viewType) {
        return inflater.inflate(R.layout.adapter_load, parent, false);
    }

    @Override
    protected ViewHolder bindHolder(View v) {
        return new ViewHolder(v);
    }

    @Override
    protected void bindData(List<MediaBean> list, ViewHolder vh, int position) {
        MediaBean bean = list.get(position);
        vh.titleTv.setText(StringUtils.getString(bean.getName()));
        vh.loadBar.setProgress(bean.getProgress());

        vh.itemContainer.setTag(position);
        vh.itemContainer.setOnClickListener(this);
    }


    class ViewHolder extends RecyclerView.ViewHolder {
        TextView titleTv;
        LoadBar loadBar;
        Button startBtn;
        LinearLayout itemContainer;

        public ViewHolder(View v) {
            super(v);
            this.titleTv = (TextView) v.findViewById(R.id.title_tv);
            this.loadBar = (LoadBar) v.findViewById(R.id.load_bar);
            this.startBtn = (Button) v.findViewById(R.id.start_btn);
            this.loadBar.setMax(100);
            this.itemContainer= (LinearLayout) v.findViewById(R.id.item_container);
        }
    }
}
